<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: global_search.php 49 2013-09-21 11:56:53Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 49 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:56:53 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require ('includes/application_top.php');

$treffer = '';

$q = $_POST['search'];

$getCustomerData = $db->db_query("SELECT
										c.customers_id,
										c.customers_cid,
										c.customers_firstname,
										c.customers_lastname,
										c.customers_email_address,
										a.entry_company
									FROM
										".TABLE_CUSTOMERS." c
									LEFT OUTER JOIN 
										".TABLE_ADDRESS_BOOK." AS a
									ON 
										(a.address_book_id = c.customers_default_address_id AND a.address_class = 'default')
									WHERE
										c.customers_id LIKE '%".$q."%'
									OR
										c.customers_cid LIKE '%".$q."%'
									OR
										a.entry_company LIKE '%".$q."%'
									OR
										c.customers_firstname LIKE '%".$q."%'
									OR
										c.customers_lastname LIKE '%".$q."%'
									OR
										c.customers_telephone LIKE '%".$q."%'
									OR
										c.customers_email_address LIKE '%".$q."%'
									GROUP BY
										c.customers_id 
									ORDER BY
										c.customers_lastname, c.customers_firstname, a.entry_company ");

if($getCustomerData->_numOfRows) {		
	$treffer  = '<h3><a href="#">' .$getCustomerData->_numOfRows.' Treffer in der Kundentabelle</a></h3>';
	$treffer .= '<div>
					<ul class="counter">';
	while(!$getCustomerData->EOF) {
		$treffer .= '<li class="w60p">
						<a href="'.href_link('customers.php', 'search='.$getCustomerData->fields['customers_cid'].'&'.getMenuID('customers')).'">
							<img class="plr5" src="images/icon_info.gif" alt="zur Übersicht" />
						</a> 
						<a href="'.href_link('customers.php', 'cID='.$getCustomerData->fields['customers_id'].'&action=edit&'.getMenuID('customers')).'">
							<img class="plr5" src="images/icon_edit.gif" alt="Adresse bearbeiten" /> 
							'.$getCustomerData->fields['customers_firstname'].' '.$getCustomerData->fields['customers_lastname'].'
							<small class="inputRequirement right"> Kd.: '.$getCustomerData->fields['customers_cid'].' '.$getCustomerData->fields['entry_company'].'</small>
						</a>
					</li>';
		$getCustomerData->MoveNext();
	}
	$treffer .= '	</ul>
				</div>';
} else
	$empty .= $getCustomerData->_numOfRows.' Treffer in der Kundentabelle<br />';
####################################################################################

$getProductsData = $db->db_query("SELECT
										p.products_id,
										p.products_model,
										pd.products_name,
										p2c.categories_id
									FROM
										".TABLE_PRODUCTS." p
										LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." AS pd
											ON (p.products_id = pd.products_id)
										LEFT JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." AS p2c
											ON (p2c.products_id = p.products_id)
									WHERE
										p.products_id LIKE '%".$q."%'
									OR
										p.products_model LIKE '%".$q."%'
									OR
										pd.products_name LIKE '%".$q."%'
									GROUP BY
										p.products_id");

if($getProductsData->_numOfRows) {
	$treffer .= '<h3><a href="#">'.$getProductsData->_numOfRows.' Treffer in Produkten</a></h3>';
	$treffer .= '<div><ul>';
	while(!$getProductsData->EOF) {
		$treffer .= '<li><a href="'.href_link('categories.php', 'cPath='.$getProductsData->fields['categories_id'].'&pID='.$getProductsData->fields['products_id'].'&action=new_product&'.getMenuID('categories')).'">'.$getProductsData->fields['products_name'].'</a></li>';
		$getProductsData->MoveNext();
	}
	$treffer .= '</ul></div>';
	
} else
	$empty .= $getProductsData->_numOfRows.' Treffer in Produkten<br />';

####################################################################################

$getOptData = $db->db_query("SELECT
									products_options_name,
									products_options_id
								FROM
									".TABLE_PRODUCTS_OPTIONS."
								WHERE
									products_options_name LIKE '%".$q."%'");

if($getOptData->_numOfRows) {
	$treffer .= '<h3><a href="#">'.$getOptData->_numOfRows.' Treffer in Produkt Optionen</a></h3>';
	$treffer .= '<div><ul>';
	while(!$getOptData->EOF) {
		$treffer .= '<li><a href="'.href_link('products_attributes.php', getMenuID('products_attributes').'&action=update_option&option_id='.$getOptData->fields['products_options_id'].'#option').'">' .$getOptData->fields['products_options_name'].'</a></li>';
		$getOptData->MoveNext();
	}
	$treffer .= '</ul></div>';
} else 
	$empty .= $getOptData->_numOfRows.' Treffer in Produkt Optionen<br />';

####################################################################################

$getValData = $db->db_query("SELECT
									products_options_values_name,
									products_options_values_id
								FROM
									".TABLE_PRODUCTS_OPTIONS_VALUES."
								WHERE
									products_options_values_name LIKE '%".$q."%'");

if($getValData->_numOfRows) {
	$treffer .= '<h3><a href="#">'.$getValData->_numOfRows.' Treffer in Produkt Merkmalen</a></h3>';
	$treffer .= '<div><ul>';
	while(!$getValData->EOF) {
		$treffer .= '<li><a href="'.href_link('products_attributes.php', getMenuID('products_attributes').'&action=update_option_value&value_id='.$getValData->fields['products_options_values_id'].'#value').'">' .$getValData->fields['products_options_values_name'].'</a></li>';
		$getValData->MoveNext();
	}
	$treffer .= '</ul></div>';
} else
	$empty .= $getOptData->_numOfRows.' Treffer in Produkt Merkmalen<br />';

####################################################################################

$getOrderData = $db->db_query("SELECT
									orders_id,
									customers_name,
									customers_email_address,
									DATE_FORMAT(date_purchased, '%d.%m.%Y %H:%i') AS date_purchased
								FROM
									".TABLE_ORDERS."
								WHERE
									orders_id LIKE '%".$q."%'
								OR
									customers_name LIKE '%".$q."%'
								OR
									customers_email_address LIKE '%".$q."%'");

if($getOrderData->_numOfRows) {
	$treffer .= '<h3><a href="#">'.$getOrderData->_numOfRows.' Treffer in Bestellungen</a></h3>';
	$treffer .= '<div><ul>';
	while(!$getOrderData->EOF) {
		$treffer .= '<li><a href="'.href_link('orders.php', getMenuID('orders').'&oID='.$getOrderData->fields['orders_id'].'&action=edit').'">'.$getOrderData->fields['orders_id'].' - '.$getOrderData->fields['customers_name'].' vom '.$getOrderData->fields['date_purchased'].'</a></li>';
		$getOrderData->MoveNext();
	}
	$treffer .= '</ul></div>';
} else
	$empty .= '0 Treffer in den Bestellungen<br />';

####################################################################################

require(DIR_WS_INCLUDES.'metatag.php');
?>
</style>
<script type="text/javascript">
	$(function(){$("#search_results").accordion({header:"h3",fx:{opacity:'toggle'},active:false,autoHeight:false});});
</script>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
	<table class="outerTable" cellspacing="0" cellpadding="0">
		<tr>
			<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
				<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
			</td>
			<td height="100%" valign="top">
	        	<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
		   			<tr>
		     			<td class="pageHeading">Globale Datenbanksuche nach <em><?php echo $q ?></em></td>
					</tr>
				</table>
				<?php if(!empty($treffer)) { ?>
				<div id="search_results">
					<?php echo $treffer; ?>
				</div><br />
				<?php } echo $empty; ?>
		    </td>
		</tr>
	</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>